<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery.js"></script>
    <script>
        var id=window.location.search;

        id=id.substring(id.indexOf('=')+1);
        //alert(id);
        $.get("grades.do",function (data) {
            let g=$("#gradeid");
            $.each(data,function(i,d){
                g.append(`<option value=${d.id}>${d.gname}</option>`)
            });
        });
        $.get("findSubject.do",{id:id},function (r) {
            if(!r.success){
                alert(r.msg);
                return false;
            }
            //填值
            $("[name=subjectname]").val(r.data.subjectname);
            $("[name=classhour]").val(r.data.classhour);
            $("[name=id]").val(r.data.id);
            $("[name=gradeid]").val(r.data.gradeid);//select选中
        });
    </script>
</head>
<body>
<div id="addDiv" >
    <form action="#" id="addForm">
       <p>
           <input type="text" readonly name="id"/>
       </p>
        <p>
            <input type="text" required name="subjectname" placeholder="课程名称"/>
        </p>
        <p>
            <input type="number" required name="classhour" min="1" placeholder="课时"/>
        </p>
        <p>
            <select name="gradeid" id="gradeid">

            </select>
        </p>
        <p>
            <input type="submit" id="btnSave" value="保存"/>
            <input type="reset" value="重填"/>
            <input type="button" value="返回"/>
        </p>
    </form>
</div>
</body>
</html>